Using Variable Functions and Attributes
This document describes how to use variable functions and attributes. Also see:
Using Variable Attributes
All IDL variables can use the dot "." operator to access various attributes that describe the variable.
All variables have special attributes that return information about the variable. These attributes are equivalent to calling the N_ELEMENTS, SIZE, or TYPENAME functions.
For example:
IDL> arr = FLTARR(200, 100)
IDL> arr.LENGTH, arr.NDIM, arr.DIM, arr.TNAME
IDL prints:
20000
2
200 100
FLOAT
See Variable Attributes for the list of available attributes.
Using Variable Functions
All IDL variables (except structures and objects) have access to function methods on "static classes," where the variable's data type determines the class. For example, an IDL variable of type BYTE has a built-in static class named IDL_Byte. The static classes have the following inheritance structure:
Note that all of IDL's integer types are a subclass of IDL_Integer, which is a subclass of IDL_Number, which in turn is a subclass of IDL_Variable. This means that all integer variables will have access to any of the functions on IDL_Integer, IDL_Number, and IDL_Variable. Similarly, all floating-point variables will have access to the functions on IDL_Number and IDL_Variable.
When a variable function is called, the IDL variable is passed into the function as the first argument. The "self" argument (normally used for object class methods) is undefined. The function can return a variable of any IDL type as the result of the call.
For example, we will use the IDL_Integer::BitShift function to divide a byte array by 2, use the IDL_Variable::Uniq function to find the unique elements, and then convert the array to a string:
IDL> arr = BYTE([146,146,146,136,136,152,152,152,66,66,66,66])
IDL> arr = arr.BitShift(-1)
IDL> HELP, arr
IDL> newarr = arr.Uniq(/NO_SORT)
IDL> HELP, newarr
IDL> print, newarr.ToASCII()
IDL prints:
ARR BYTE = Array[12]
NEWARR BYTE = Array[4]
IDL!
See Also